package com.study.cloud.controller;

import com.study.cloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
@RequestMapping(value = "/payment/")
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String serverPort;

    @RequestMapping(value = "hystrix/ok/{id}", method = RequestMethod.GET)
    public String paymentInfo_ok(@PathVariable("id") Integer id) {
        String result = paymentService.paymentInfo_ok(id);
        log.info("==============>result：" + result);
        return result;
    }

    @RequestMapping(value = "hystrix/error/{id}", method = RequestMethod.GET)
    public String paymentInfo_error(@PathVariable("id") Integer id) {
        String result = paymentService.paymentInfo_error(id);
        log.info("==============>result：" + result);
        return result;
    }

    //============服务熔断
    @RequestMapping(value = "hystrix/circuit/{id}", method = RequestMethod.GET)
    public String paymentCircuitBreaker(@PathVariable("id") Integer id) {
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("==============>result：" + result);
        return result;
    }
}
